from django.db import models

# Create your models here.

from datetime import datetime


# 用户表
class UserModel(models.Model):
    username = models.CharField(max_length=32)
    mobile = models.CharField(max_length=11)
    password = models.CharField(max_length=256)
    money = models.DecimalField(max_digits=10,decimal_places=2,default=0)
    level=models.IntegerField(verbose_name='等级',default=0)
    lock_money = models.DecimalField(max_digits=10, decimal_places=2, default=0)
    user_type = models.IntegerField(default=0,verbose_name='1 雇主 2 服务商')
    status = models.IntegerField(default=0, verbose_name='0 默认 1 会员')
    images=models.CharField(max_length=256,default='')
    create_time = models.DateTimeField(default=datetime.now())

    def __str__(self):
        return self.username

    class Meta:
        db_table = 'user'



# #### 5.三方登录表
# 用户id、三方平台、token、uid，三方平台地址
class SfLogin(models.Model):
    __tablename__="sf_login"
    userid = models.ForeignKey(to=UserModel,  on_delete=models.CASCADE)
    webfrom = models.CharField(max_length=30)
    token = models.CharField(max_length=128)
    uid = models.CharField(max_length=100)
    url = models.CharField(max_length=256)

    def __str__(self):
        return self.userid

    class Meta:
        db_table = 'sf_login'



#合同表
class ContractModel(models.Model):
    name = models.CharField(max_length=30)
    content = models.TextField()
    url = models.CharField(max_length=256,default='')
    type = models.IntegerField(default=1)
    def __str__(self):
        return self.name
    class Meta:
        db_table = 'contract'

#用户签订合同
class ContractUserModel(models.Model):
    user_id = models.ForeignKey(to=UserModel,  on_delete=models.CASCADE)
    contract_id = models.IntegerField()
    def __str__(self):
        return self.user_id
    class Meta:
        db_table = 'user_contract'


# 企业表
class CompanyModel(models.Model):
    companies_name = models.CharField(max_length=32, verbose_name='企业名称')
    juridical_person = models.CharField(max_length=16, verbose_name='法人',default='')
    code=models.CharField(max_length=100,verbose_name='企业认证码',default='')
    mobile = models.CharField(max_length=11)
    scale=models.CharField(max_length=10,default='')  # 规模
    address = models.CharField(max_length=64, verbose_name='企业地址')

    def __str__(self):
        return self.companies_name
    class Meta:
        db_table = 'company'

# 企业与个人关联表
class CompanyUserModel(models.Model):
    user_id = models.IntegerField()
    companies_id = models.IntegerField()

    def __str__(self):
        return self.user_id
    class Meta:
        db_table = 'company_user'


#用户账户金额记录表
class UserAmount_record(models.Model):
    money = models.DecimalField(max_digits=10, decimal_places=2)
    create_time = models.DateTimeField(default=datetime.now())
    type=models.IntegerField(verbose_name='1 + 2 -')
    status=models.IntegerField(verbose_name='0 充值或提现 1 订单') # 3 购买会员
    user_id = models.IntegerField()

    def __str__(self):
        return self.money
    class Meta:
        db_table = 'user_amount'

#  vip记录表 用户id  开始时间  结束时间
class VipModel(models.Model):
    __tablename__="vip"
    userid = models.ForeignKey(to=UserModel, on_delete=models.CASCADE)
    start_time = models.DateTimeField(default=datetime.now())
    end_time = models.DateTimeField()
# #### vip购买记录订单表

# 用户id、购买年限、金额、折扣、实际第三方支付金额、支付状态
class VipRecordModel(models.Model):
    __tablename__="vip_record"
    order_id=models.CharField(max_length=30,default='')
    userid = models.ForeignKey(to=UserModel, on_delete=models.CASCADE)
    year = models.IntegerField(verbose_name='年',default=1)
    money = models.DecimalField(max_digits=8,decimal_places=2,default=365)
    discount = models.DecimalField(max_digits=8,decimal_places=2,default=0)
    active_money = models.DecimalField(max_digits=8,decimal_places=2,default=365)
    status = models.IntegerField(verbose_name='支付状态 1 正常 2 失败',default=0)
    create = models.DateTimeField(default=datetime.now())

class RechargeModel(models.Model):  # 充值记录表
    order_id = models.CharField(max_length=30, default='')
    userid = models.ForeignKey(to=UserModel, on_delete=models.CASCADE)
    money = models.DecimalField(max_digits=8, decimal_places=2)
    status = models.IntegerField(verbose_name='支付状态 1 正常 2 失败', default=0)
    type = models.IntegerField(verbose_name='平台类型',default=1)
    create = models.DateTimeField(default=datetime.now())
    def __str__(self):
        return self.order_id
    class Meta:
        db_table = 'recharge_model'

class Trade_TypeModel(models.Model):  # 个人行业类型表  只有一二级分类
    name = models.CharField(max_length=30)
    pid = models.IntegerField(verbose_name='自关联')

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'trade_type'

class Classify(models.Model):   # 服务分类表
    name=models.CharField(max_length=30)
    pid=models.IntegerField(verbose_name='无限自关联')
    def __str__(self):
        return self.name
    class Meta:
        db_table = 'classify'

class ProfessionType(models.Model):   # 服务商职业技术分类表
    name = models.CharField(max_length=30)
    pid = models.IntegerField(verbose_name='无限自关联')

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'profession_type'


class User_certification(models.Model):   # 实名认证表
    userid = models.ForeignKey(to=UserModel, on_delete=models.CASCADE)
    name=models.CharField(max_length=30,verbose_name='真实姓名')
    code=models.CharField(verbose_name='身份证id',max_length=30)
    create_time = models.DateTimeField(default=datetime.now())
    class Meta:
        db_table = 'user_certification'


class ProjectDemandModel(models.Model):   # 按项目   (项目需求表)
    code = models.BigIntegerField()  # 用于审核
    userid = models.ForeignKey(to=UserModel, on_delete=models.CASCADE)
    title=models.CharField(max_length=20,verbose_name='标题')
    describes=models.TextField(verbose_name='需求描述')
    file_url=models.CharField(default='',verbose_name='文件路径',max_length=128)
    price = models.DecimalField(max_digits=10, decimal_places=2)
    max_price = models.DecimalField(max_digits=10, decimal_places=2,default=0)
    need_id = models.IntegerField(verbose_name='需求的标签')
    way_type=models.IntegerField(verbose_name='方式类型')  # 比稿（自己选择其中一个） 招标（找人）
    review_status = models.IntegerField(default=0, verbose_name='0 未审核 1 审核通过 2 审核未通过')
    audit_userid=models.IntegerField(default=0,verbose_name='审核人id')
    create_time = models.DateTimeField(default=datetime.now())
    class Meta:
        db_table = 'project_demand'

class ProjectDemand1Model(models.Model):   # 按项目
    code = models.BigIntegerField()
    userid = models.ForeignKey(to=UserModel, on_delete=models.CASCADE)
    title=models.CharField(max_length=20,verbose_name='标题')
    describes=models.TextField(verbose_name='需求描述')
    file_url = models.CharField(default='', verbose_name='文件路径',max_length=128)
    price = models.DecimalField(max_digits=10, decimal_places=2)
    max_price = models.DecimalField(max_digits=10, decimal_places=2,default=0)
    need_id = models.IntegerField(verbose_name='需求的标签')  # 服务分类
    # project_type=models.IntegerField(verbose_name='项目类型')
    way_type=models.IntegerField(verbose_name='方式类型')  # 比稿（自己选择其中一个） 招标（找人）
    review_status = models.IntegerField(default=0, verbose_name='0 未审核 1 审核通过 2 审核未通过')
    audit_userid = models.IntegerField(default=0, verbose_name='审核人id')
    create_time = models.DateTimeField(default=datetime.now())
    class Meta:
        db_table = 'project_demand1'


class ProjectDemand2Model(models.Model):   # 按项目
    code = models.BigIntegerField()
    userid = models.ForeignKey(to=UserModel, on_delete=models.CASCADE)
    title=models.CharField(max_length=20,verbose_name='标题')
    describes=models.TextField(verbose_name='需求描述')
    file_url = models.CharField(default='', verbose_name='文件路径',max_length=128)
    price = models.DecimalField(max_digits=10, decimal_places=2)
    max_price = models.DecimalField(max_digits=10, decimal_places=2,default=0)
    need_id = models.IntegerField(verbose_name='需求的标签')
    way_type=models.IntegerField(verbose_name='方式类型')  # 比稿（自己选择其中一个） 招标（找人）
    review_status = models.IntegerField(default=0, verbose_name='0 未审核 1 审核通过 2 审核未通过')
    audit_userid = models.IntegerField(default=0, verbose_name='审核人id')
    create_time = models.DateTimeField(default=datetime.now())
    class Meta:
        db_table = 'project_demand2'


class ProjectDemandTimeModel(models.Model):   # 按时间计费
    code = models.BigIntegerField(default=0)
    userid = models.ForeignKey(to=UserModel, on_delete=models.CASCADE)
    title=models.CharField(max_length=20,verbose_name='标题')
    describes=models.TextField(verbose_name='需求描述')
    file_id=models.IntegerField(default=0)  # 文件id
    hour_price = models.DecimalField(max_digits=10, decimal_places=2)   # 每小时时薪
    hire_time=models.IntegerField()  # 雇佣时长
    daily=models.IntegerField()  # 日均工时
    settlement_type=models.CharField(verbose_name='结算方式',max_length=10)
    need_id = models.IntegerField(verbose_name='需求的标签')  # 变成人才类型
    review_status = models.IntegerField(default=0, verbose_name='0 未审核 1 审核通过 2 审核未通过')
    audit_userid = models.IntegerField(default=0, verbose_name='审核人id')
    create_time = models.DateTimeField(default=datetime.now())
    class Meta:
        db_table = 'project_demand_time'

class ProjectDemandTime1Model(models.Model):   # 按时间计费
    code = models.BigIntegerField(default=0)
    userid = models.ForeignKey(to=UserModel, on_delete=models.CASCADE)
    title=models.CharField(max_length=20,verbose_name='标题')
    describes=models.TextField(verbose_name='需求描述')
    file_id=models.IntegerField(default=0)  # 文件id
    hour_price = models.DecimalField(max_digits=10, decimal_places=2)   # 每小时时薪
    hire_time=models.IntegerField()  # 雇佣时长
    daily=models.IntegerField()  # 日均工时
    settlement_type=models.CharField(verbose_name='结算方式',max_length=10)
    need_id = models.IntegerField(verbose_name='需求的标签')  # 变成人才类型
    review_status = models.IntegerField(default=0, verbose_name='0 未审核 1 审核通过 2 审核未通过')
    audit_userid = models.IntegerField(default=0, verbose_name='审核人id')
    create_time = models.DateTimeField(default=datetime.now())
    class Meta:
        db_table = 'project_demand_time1'

class ProjectDemandTime2Model(models.Model):   # 按时间计费
    code = models.BigIntegerField(default=0)
    userid = models.ForeignKey(to=UserModel, on_delete=models.CASCADE)
    title=models.CharField(max_length=20,verbose_name='标题')
    describes=models.TextField(verbose_name='需求描述')
    file_id=models.IntegerField(default=0)  # 文件id
    hour_price = models.DecimalField(max_digits=10, decimal_places=2)   # 每小时时薪
    hire_time=models.IntegerField()  # 雇佣时长
    daily=models.IntegerField()  # 日均工时
    settlement_type=models.CharField(verbose_name='结算方式',max_length=10)
    need_id = models.IntegerField(verbose_name='需求的标签')  # 变成人才类型
    review_status = models.IntegerField(default=0, verbose_name='0 未审核 1 审核通过 2 审核未通过')
    audit_userid = models.IntegerField(default=0, verbose_name='审核人id')
    create_time = models.DateTimeField(default=datetime.now())
    class Meta:
        db_table = 'project_demand_time2'

class ShopModel(models.Model):
    shop_name = models.CharField(max_length=32,verbose_name='商铺名')
    describe = models.TextField(verbose_name='介绍描述')
    images = models.CharField(max_length=256, default='')
    score=models.DecimalField(max_digits=2,decimal_places=1,default=3)
    user_id = models.IntegerField()
    def __str__(self):
        return self.shop_name
    class Meta:
        db_table = 'shop'

#商品表
class GoodsModel(models.Model):
    good_name = models.CharField(max_length=32,verbose_name='商品名')
    price = models.DecimalField(max_digits=10,decimal_places=2,default=0)
    images=models.CharField(max_length=256)
    good_type=models.IntegerField()
    shop_id = models.IntegerField(verbose_name='商铺外键')
    def __str__(self):
        return self.good_name
    class Meta:
        db_table = 'goods'



#订单表
class OrdersModel(models.Model):
    order_code = models.BigIntegerField(primary_key=True)  # 订单号
    user_id = models.IntegerField()   # 雇主
    order_type=models.IntegerField(default=1)  # 1 2 3  招标 比稿 服务
    seller_id = models.IntegerField(verbose_name='id')   # 当为外包时 此id时需求id  当为服务时 此为服务id
    price = models.DecimalField(max_digits=10, decimal_places=2)   # 价钱
    pay_status = models.IntegerField(default=0, verbose_name='1 为未支付 2 为支付完成 3失败')  # 支付状态
    create_time = models.DateTimeField(default=datetime.now())
    def __str__(self):
        return self.order_code
    class Meta:
        db_table = 'orders'
#
#
# #订单历史记录表
# class OrderRecordModel(models.Model):
#     user_id = models.IntegerField(verbose_name='买家id')
#     order_code = models.BigIntegerField(verbose_name='所属订单')
#     seller_id = models.IntegerField(verbose_name='卖家id')
#     goods_price = models.DecimalField(max_digits=10, decimal_places=2)
#     create_time = models.DateTimeField(default=datetime.now())
#
#     def __str__(self):
#         return self.order_code
#
#     class Meta:
#         db_table = 'order_record'









#
# #服务商个人详细信息
# class ServiceAbilityModel(models.Model):
#     job_age = models.CharField(max_length=36,verbose_name='工作经验')
#     introduce = models.TextField()
#     user_id = models.IntegerField()
#     create_datetime = models.DateTimeField(default=datetime.now())
#     def __str__(self):
#         return self.user_id
#     class Meta:
#         db_table = 'service_ability'
#


# #购物车表
# class ShoppingCartModel(models.Model):
#     user_id = models.IntegerField()
#     shop_id = models.IntegerField()
#     goods_id = models.IntegerField()
#     goods_count = models.IntegerField()
#     goods_price = models.DecimalField(max_digits=10,decimal_places=2)
#     def __str__(self):
#         return self.user_id
#     class Meta:
#         db_table = 'shopping_cart'
#






























